import type { AddCartParams, CartItem } from '@/types/cart'
import { http } from '@/utils/http'

/**
 * 加入购物车的接口方法
 * @param data:{skuId:string,count:number}
 * @returns
 */
export const addCartAPI = (data: AddCartParams) => http.post('/member/cart', data)
/**
 * 获取购物车商品列表的接口方法
 * @returns 购物车商品列表
 */
export const getCartListAPI = () => http.get<CartItem[]>('/member/cart')
/**
 * 删除购物车中商品的接口方法
 * @param data {ids} SKUID集合
 */
export const deleteCartAPI = (data: { ids: string[] }) =>
  http.delete('/member/cart', data)
/**
 * 更新购物车商品的接口方法
 * @param skuId skuId
 * @param data {selected?:是否选中,count?:数量}
 */
export const updateCartAPI = (
  skuId: string,
  data: { selected?: boolean; count?: number },
) => http.put(`/member/cart/${skuId}`, data)
/**
 * 更新商品是否全选的接口方法
 * @param data {selected:是否全选}
 */
export const updateAllSelectedAPI = (data: { selected: boolean }) =>
  http.put('/member/cart/selected', data)
